package com.dhcc.bpm.alarm.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.dhcc.bpm.common.utils.http.RestHttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TaskAsyncService {
	
	@Autowired
	RestHttpUtil restHttpUtil;
	
	@Value("${taskConfig.taskNotifyUrl}")
	private String taskNotifyUrl;
	
	/**
	 * @Descriptin 定时任务异步通知
	 * @param taskParam 
	 *       D定时任务请求参数（包含taskBatchNo, traceNo）
	 * @param rsSts  
	 *       00-执行成功  else-执行失败
	 *       01-未执行
	 *       02-执行中(当触发模式为循环时，此字段状态默认为 1)
	 *       03-执行失败
	 * @param rsMsg 
	 *       M执行结果信息，记录到定时任务表中的
	 */
	@Async
	public void resultNotice(JSONObject taskParam, String rsSts, String rsMsg) {
			
		log.info("定时任务异步通知 -----{}--------", taskParam.get("taskBatchNo"));
		JSONObject object = new JSONObject();
		object.put("taskBatchNo", taskParam.getString("taskBatchNo"));
		object.put("traceNo", taskParam.getString("traceNo"));
		object.put("sts", rsSts);	
		object.put("msg", rsMsg);
		
		try {
			log.info("定时任务异步通知请求报文：{}", object);
			JSONObject notifyRs =  restHttpUtil.sendPost(taskNotifyUrl, object);
			log.info("定时任务异步通知 结果:{}", notifyRs);
		} catch (Exception e) {
			log.info("定时任务异步通知 异常:  {}", e);
		}
		
       
	}
}
